package com.bluefish.bltuan.service.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.bluefish.bltuan.dao.MsgDao;
import com.bluefish.bltuan.module.Category;
import com.bluefish.bltuan.module.msg.Message;
import com.bluefish.bltuan.module.msg.MessageType;
import com.bluefish.bltuan.service.MsgService;
import com.bluefish.bltuan.util.PageIndex;

@Service
public class MsgServiceImpl implements MsgService{

	private MsgDao msgDao;
	
	public void delete(Message t) {
		this.msgDao.delete(t);
	}

	public Message findById(Integer id) {
		return this.msgDao.findById(id);
	}

	public void save(Message t) {
		this.msgDao.save(t);
	}

	public void update(Message t) {
		this.msgDao.update(t);
	}
	
	public void setMsgDao(MsgDao msgDao) {
		this.msgDao = msgDao;
	}

	public int countQuestions() {
		return this.msgDao.countByType(MessageType.QUESTION);
	}

	public List<Message> listQuestions(PageIndex pageIndex) {
		return this.msgDao.listByType(MessageType.QUESTION, pageIndex);
	}

	public List<Message> listQuestions(int number) {
		return this.msgDao.listByType(MessageType.QUESTION, number);
	}
	
	public List<Message> listQuestions(PageIndex pageIndex, Category currentCity) {
		return this.msgDao.listByTypeAndCity(pageIndex, MessageType.QUESTION, currentCity);
	}
	
	public List<Message> listTransfers(PageIndex pageIndex, Category currentCity) {
		return this.msgDao.listByTypeAndCity(pageIndex, MessageType.TRANSFER, currentCity);
	}

}
